<?php
require_once("../includes/config.php");
require_once("../includes/functions/func.global.php");
require_once("../includes/functions/loggincheck.php");
require_once('../includes/lang/admin/lang_'.$config['lang'].'.php');
require_once("class.menu.php");

// Connect to database
db_connect($config);
	
$error = '';

if(isset($_POST['url']))
{
	$user_id = mysql_fetch_row(mysql_query("SELECT user_id FROM `".$config['db']['pre']."users` WHERE username='".addslashes($_POST['username'])."' LIMIT 1"));

	if($user_id[0])
	{
		mysql_query("INSERT INTO `".$config['db']['pre']."feeds` ( `feed_id` , `feed_url` , `feed_lastch` , `feed_cat` , `feed_period` , `feed_user` ) VALUES ('', '".addslashes($_POST['url'])."', '0', '".addslashes($_POST['cat'])."', '".addslashes($_POST['period'])."', '".addslashes($user_id[0])."');");

		header("Location: feeds_view.php");
		exit;
	}
	else
	{
		$error = 'Username does not exist';
	}
}

$obj = new Menu();
$nav = $obj->get_js_menu(0,$config,$lang);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PHPDug Admin - <?php echo $lang['ADDFEED']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="images/style.css">
<SCRIPT LANGUAGE="JavaScript" SRC="menu/JSCookMenu.js"></SCRIPT>
<LINK REL="stylesheet" HREF="menu/themes/Office/theme.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="menu/themes/Office/theme.js"></SCRIPT>
<LINK REL="stylesheet" HREF="menu/themes/Office/theme.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="menu/themes/Office/theme.js"></SCRIPT>
<script language="JavaScript"><!--
function checkBox(theBox){
  var aBox = theBox.form["list[]"];
  var selAll = false;
  var i;
  for(i=0;i<aBox.length;i++){
    if(aBox[i].checked==false) selAll=true;
  }
  if(theBox.name=="selall"){
    for(i=0;i<aBox.length;i++){
      aBox[i].checked = selAll;
    }
    selAll = !selAll;
  }
  //theBox.form.selall.checked = selAll;
}
function init(){
  var theForm = document.f1;
  var aBox = theForm["list[]"];
  var selAll = false;
  var i;
  for(i=0;i<aBox.length;i++){
    if(aBox[i].checked==false) selAll=true;
    aBox[i].onclick = function(){checkBox(this)};
  }
  //theForm.selall.checked = selAll;
}
function change_feed(value)
{
	document.getElementById('url').value = value;
}
//--></script>
</head>
<body>
<!--Start top-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="100%" height="42" align="left" background="images/bg_top.gif"><a href="index.php"><img src="images/logo.gif" width="127" height="37" hspace="10" border="0"></a></td>
  </tr>
  <tr>
    <td><img src="images/dot.gif" width="1" height="1" alt=""></td>
  </tr>
</table>
<!--End top-->
<!--Start topmenu-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#F0F0F0" height="25" style="padding-left:20px;" id="menu"><SCRIPT language="JavaScript" type="text/javascript">
			var myMenu =
				
			// Start the menu
[
<?php echo $nav; ?>
];				

			// Output the menu
			cmDraw ('menu', myMenu, 'hbr', cmThemeOffice, 'ThemeOffice');
			</SCRIPT></td>
  </tr>
  <tr>
    <td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
  </tr>
</table>
<br>

<!--End topmenu-->
<!--Start heading page-->
<table width="850" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td class="heading"><img src="images/icons/icon_addrule.gif" width="21" height="22" alt="" align="absmiddle" hspace="5"><?php echo $lang['ADDFEED']; ?></td>
</tr>
<tr>
<td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
</tr>
</table>
<!--End heading page-->
<!--Start form-->
<br>
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #CCCCCC;">
  <tr>
    <td align="center" bgcolor="#F6F6F6" style="padding:15px;">
	<form name="form1" method="post" action="feeds_add.php">
	<? if($error != ''){ echo $error.'<br><br><br>'; } ?>
        <table width="70%" cellpadding="0" cellspacing="2" border="0">
          <tr>
            <td width="25%"><strong><?php echo $lang['FEEDURL']; ?></strong></td>
            <td width="55%">:
                <input name="url" type="Text" class="textbox" id="url" style="width:60%" value="<? if(isset($_POST['url'])){ echo $_POST['url']; } ?>"></td>
          </tr>
          <tr>
            <td width="25%">&nbsp;</td>
            <td width="55%"><?php echo $lang['OR']; ?></td>
          </tr>
          <tr>
            <td width="25%"><strong>Digg.com Feed</strong></td>
            <td width="55%">:
                <select name="digg_feed" class="textbox" style="width:60%" onChange="change_feed(this.value);">
				  <option value="">Select Feed</option>
				  <optgroup label="View All">
                  <option value="http://www.digg.com/rss/index.xml">Popular</option>
                  <option value="http://www.digg.com/rss/indexdig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="Technology">
                  <option value="http://www.digg.com/rss/containertechnology.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containertechnologydig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="Science">
                  <option value="http://www.digg.com/rss/containerscience.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containersciencedig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="World & Business">
                  <option value="http://www.digg.com/rss/containerworld_business.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containerworld_businessdig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="Sports">
                  <option value="http://www.digg.com/rss/containersports.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containersportsdig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="Entertainment">
                  <option value="http://www.digg.com/rss/containerentertainment.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containerentertainmentdig.xml">Upcoming</option>
				  </optgroup>
				  <optgroup label="Gaming">
                  <option value="http://www.digg.com/rss/containergaming.xml">Popular</option>
                  <option value="http://www.digg.com/rss/containergamingdig.xml">Upcoming</option>
				  </optgroup>
                </select></td>
          </tr>
          <tr>
            <td width="25%">&nbsp;</td>
            <td width="55%"></td>
          </tr>
          <tr>
            <td width="25%"><strong><?php echo $lang['FEEDCAT']; ?></strong></td>
            <td width="55%">:
                <select name="cat" class="textbox" style="width:60%">
                  <?php
$query = "SELECT cat_id,cat_title FROM ".$config['db']['pre']."cats ORDER BY cat_title ASC";
$query_result = mysql_query($query);
while ($info = @mysql_fetch_array($query_result))
{
?>
                  <option value="<?=$info['cat_id'];?>" <? if(isset($_POST['cat'])){ if($_POST['cat'] == $info['cat_id']){ echo 'selected'; } } ?>><?=stripslashes($info['cat_title']);?></option>
                  <?php
}
?>
                </select></td>
          </tr>
          <tr>
            <td width="25%"><strong>Feed Period</strong></td>
            <td width="55%">:
                <select name="period" class="textbox" style="width:60%">
				<option value="3600">1 Hour</option>
				 <option value="21600">6 Hours</option>
				 <option value="43200">12 Hours</option>
                  <option value="86400" selected>24 Hours</option>
                </select></td>
          </tr>
          <tr>
            <td width="25%"><strong><?php echo $lang['USERNAME']; ?> (<?php echo $lang['VALIDUSER']; ?>)</strong></td>
            <td width="55%">:
                <input name="username" type="text" class="textbox" id="username" style="width:60%" value="<? if(isset($_POST['username'])){ echo $_POST['username']; } ?>"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td></td>
            <td height="30" style="padding-left:6px;"><input name="Submit" type="submit" class="button" value="<?php echo $lang['SUBMIT']; ?>">
&nbsp;
            <input name="Reset" type="reset" class="button" value="<?php echo $lang['RESET']; ?>">
            </td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
<!--End form-->
<br><br>
<!--Start bottom-->
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#333333"><img src="images/dot.gif" width="1" height="1" alt=""></td>
</tr>
<tr>
<td style="padding:15px;" align="center">
<span class="copyright">Copyright &copy; 2011 <a href="http://www.kubelabs.com/phpdug/" class="copyright" target="_blank">Kubelabs.com</a> All Rights Reserved.</span></td>
</tr>
</table>
<!--End bottom-->
</body>
</html>